package com.honey.mybatis.generator.model;

import java.util.List;

import com.honey.compilation.java.AbstractJavaCompilation;
import com.honey.compilation.java.ClassDecoration;
import com.honey.compilation.java.EnumField;
import com.honey.compilation.java.InnerEnum;
import com.honey.compilation.java.JavaVisibility;
import com.honey.compilation.java.Parameter;
import com.honey.core.compiler.CompilationException;
import com.honey.core.dbmapping.introspect.IntrospectSchema;
import com.honey.core.dbmapping.introspect.IntrospectSchemaColumn;
import com.honey.core.dbmapping.structure.Column;
import com.honey.core.dbmapping.structure.Schema;
import com.honey.core.types.FullyQualifiedJavaType;
import com.honey.core.types.JDKFullyQualifiedJavaType;
import com.honey.mybatis.generator.AbstractClass;
import com.honey.mybatis.generator.MybatisPlugin;

public class TableColumnEnum extends AbstractClass{
	
	public TableColumnEnum(MybatisPlugin belongPlugin,
			IntrospectSchema introspectSchema,
			IntrospectSchemaColumn introspectSchemaColumn) {
		super(belongPlugin, introspectSchema, introspectSchemaColumn);
		
	}
	
	/* (non-Javadoc)
	 * @see com.honey.mybatis.generator.AbstractClass#getAbstractJavaCompilation()
	 */
	@Override
	protected AbstractJavaCompilation getAbstractJavaCompilation()
			throws CompilationException {
		InnerEnum answer = null;
		Schema schema= introspectSchema.getSchema();
		answer = new InnerEnum(super.getTableColumnEnumClassType(schema),new ClassDecoration(JavaVisibility.PUBLIC));
		addEnumValue(answer);
		return answer ;
	}
	
	/**
	 * 
	 * @param inner
	 */
	private final void addEnumValue(InnerEnum inner ){
		List<Column> columns= introspectSchemaColumn.allColumns();
		EnumField enumField = null; Parameter parameter = null;
		
		for(Column column : columns ){
			enumField  = new EnumField(super.getFieldName(column).toUpperCase() , column.getComment());
			parameter = new Parameter(JDKFullyQualifiedJavaType.getStringInstance(),column.getName());
			enumField.addParameter(parameter,column.getName());
			inner.addEnumFields(enumField);
		}
	}
	
	@Override
	protected FullyQualifiedJavaType getType() {
		
		return null;
	}

}
